package testen;

import static org.junit.Assert.*;

import java.awt.Color;
import org.junit.Test;
import puzzeldoolhof.Game;
import puzzeldoolhof.Position;
import puzzeldoolhof.State;
import weighteddirectedgraph.WeightedDirectedGraph;

public class puzzeldoolhof_Test {

	private Game spel = new Game();
	private WeightedDirectedGraph<Position, Color> graaf = new WeightedDirectedGraph<Position, Color>();
	private State speler;
	private Position pFinish = new Position(0,Color.BLUE);

	@Test
	public void puzzeldoolhof_1Position_finish() {
		speler = new State( pFinish, pFinish );
		graaf.addItem( pFinish );
		spel.setMaze( graaf );
		assertEquals( "[0|0]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_1Position_geenFinish() {
		Position p1 = new Position( 1, Color.BLACK );
		speler = new State( p1 , p1);
		graaf.addItem( p1 );
		graaf.addItem( pFinish );
		spel.setMaze( graaf );
		assertEquals( "[]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_2Position_finish() {
		Position p1 = new Position( 1, Color.BLACK );
		speler = new State( p1 , p1 );
		graaf.addItem( p1 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, pFinish, Color.BLACK );
		spel.setMaze( graaf );
		assertEquals( "[1|1, 0|1]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_2Position_finish2() {
		Position p1 = new Position( 1, Color.BLACK );
		Position p2 = new Position( 2, Color.RED );
		speler = new State( p1, p2);
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( pFinish );
		graaf.addEdge( p2, pFinish, Color.BLACK );
		spel.setMaze( graaf );
		assertEquals( "[1|2, 0|1]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_4Position_loopGeenFinish() {
		Position p1 = new Position( 1, Color.BLACK );
		Position p2 = new Position( 2, Color.RED );
		Position p3 = new Position( 3, Color.GREEN);
		speler = new State( p1, p1 );
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( p3 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, p2, Color.BLACK );
		graaf.addEdge( p2, p3, Color.BLACK );
		graaf.addEdge( p3, p1, Color.BLACK );
		spel.setMaze( graaf );
		assertEquals( "[]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_5Position_Finish() {
		Position p1 = new Position( 1, Color.BLACK );
		Position p2 = new Position( 2, Color.RED );
		Position p3 = new Position( 3, Color.GREEN);
		Position p4 = new Position( 4, Color.YELLOW);

		speler = new State( p1 , p3);
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( p3 );
		graaf.addItem( p4 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, p2, Color.BLACK );
		graaf.addEdge( p2, p3, Color.BLACK );
		graaf.addEdge( p3, p1, Color.BLACK );
		graaf.addEdge( p1, p4, Color.GREEN );
		graaf.addEdge( p4, pFinish, Color.GREEN );
		graaf.addEdge( p4, p1, Color.GREEN );
		spel.setMaze( graaf );
		assertEquals( "[1|3, 3|4, 0|3]", spel.findPath( speler, pFinish ).toString() );
	}

	@Test
	public void puzzeldoolhof_5Position_FinishSpeler2() {
		Position p1 = new Position( 1, Color.BLACK );
		Position p2 = new Position( 2, Color.RED );
		Position p3 = new Position( 3, Color.GREEN);
		Position p4 = new Position( 4, Color.YELLOW);

		speler = new State( p1, p3 );
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( p3 );
		graaf.addItem( p4 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, p2, Color.GREEN );
		graaf.addEdge( p3, p4, Color.RED );
		graaf.addEdge( p4, pFinish, Color.RED );
		spel.setMaze( graaf );
		assertEquals( "[1|3, 2|3, 2|4, 0|2]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_5Position_moveSpeler1_moveSpeler2_finishSpeler1() {
		Position p1 = new Position( 1, Color.BLACK );
		Position p2 = new Position( 2, Color.RED );
		Position p3 = new Position( 3, Color.GREEN);
		Position p4 = new Position( 4, Color.YELLOW);

		speler = new State( p1, p3 );
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( p3 );
		graaf.addItem( p4 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, p2, Color.GREEN );
		graaf.addEdge( p3, p4, Color.RED );
		graaf.addEdge( p2, pFinish, Color.YELLOW );
		spel.setMaze( graaf );
		assertEquals( "[1|3, 2|3, 2|4, 0|4]", spel.findPath( speler, pFinish ).toString() );
	}
	
	@Test
	public void puzzeldoolhof_reader(){
		Position p1		 = new Position( 1, Color.RED );
		Position p2 	 = new Position( 2, Color.BLACK );
		Position p3 	 = new Position( 3, Color.GREEN);
		Position p4		 = new Position( 4, Color.GREEN);
		Position p5 	 = new Position( 5, Color.GREEN);
		Position p6 	 = new Position( 6, Color.YELLOW);
		Position p7 	 = new Position( 7, Color.YELLOW);
		Position p8 	 = new Position( 8, Color.RED);
		Position p9 	 = new Position( 9, Color.RED);
		Position p10 	 = new Position( 10, Color.BLACK);
		Position p11 	 = new Position( 11, Color.YELLOW);
		Position p12 	 = new Position( 12, Color.RED);
		Position p13 	 = new Position( 13, Color.YELLOW);
		Position p14 	 = new Position( 14, Color.GREEN);
		Position p15 	 = new Position( 15, Color.YELLOW);
		Position p16	 = new Position( 16, Color.GREEN);
		Position p17 	 = new Position( 17, Color.GREEN);
		Position p18 	 = new Position( 18, Color.BLACK);
		Position p19 	 = new Position( 19, Color.YELLOW);
		Position p20 	 = new Position( 20, Color.GREEN);
		Position p21	 = new Position( 21, Color.BLACK);
		Position p22	 = new Position( 22, Color.BLACK);

		speler = new State( p1, p2 );
		graaf.addItem( p1 );
		graaf.addItem( p2 );
		graaf.addItem( p3 );
		graaf.addItem( p4 );
		graaf.addItem( p5 );
		graaf.addItem( p6 );
		graaf.addItem( p7 );
		graaf.addItem( p8 );
		graaf.addItem( p9 );
		graaf.addItem( p10 );
		graaf.addItem( p12 );
		graaf.addItem( p12 );
		graaf.addItem( p13 );
		graaf.addItem( p14 );
		graaf.addItem( p15 );
		graaf.addItem( p16 );
		graaf.addItem( p17 );
		graaf.addItem( p18 );
		graaf.addItem( p19 );
		graaf.addItem( p20 );
		graaf.addItem( p21 );
		graaf.addItem( p22 );
		graaf.addItem( pFinish );
		graaf.addEdge( p1, p4, Color.RED );
		graaf.addEdge( p1, p5, Color.BLACK );
		graaf.addEdge( p2, p6, Color.GREEN );
		graaf.addEdge( p2, p12, Color.RED );
		graaf.addEdge( p3, p1, Color.YELLOW );
		graaf.addEdge( p3, p4, Color.YELLOW );
		graaf.addEdge( p4, p13, Color.BLACK );
		graaf.addEdge( p5, p9, Color.YELLOW );
		graaf.addEdge( p6, p9, Color.GREEN );
		graaf.addEdge( p6, p10, Color.RED );
		graaf.addEdge( p7, p2, Color.GREEN );
		graaf.addEdge( p8, p3, Color.RED );
		graaf.addEdge( p9, p4, Color.GREEN );
		graaf.addEdge( p9, p14, Color.BLACK );
		graaf.addEdge( p10, p15, Color.GREEN );
		graaf.addEdge( p11, p10, Color.RED );
		graaf.addEdge( p11, p12, Color.GREEN );
		graaf.addEdge( p12, p7, Color.GREEN );
		graaf.addEdge( p13, p8, Color.GREEN );
		graaf.addEdge( p13, p18, Color.GREEN );
		graaf.addEdge( p14, p20, Color.YELLOW );
		graaf.addEdge( p14, pFinish, Color.GREEN );
		graaf.addEdge( p15, p22, Color.GREEN );
		graaf.addEdge( p15, pFinish, Color.RED );
		graaf.addEdge( p16, p15, Color.GREEN );
		graaf.addEdge( p17, p11, Color.BLACK );
		graaf.addEdge( p17, p12, Color.RED );
		graaf.addEdge( p17, p16, Color.BLACK );
		graaf.addEdge( p18, p9, Color.YELLOW );
		graaf.addEdge( p18, p20, Color.YELLOW );
		graaf.addEdge( p19, p18, Color.GREEN );
		graaf.addEdge( p20, p19, Color.BLACK );
		graaf.addEdge( p20, p21, Color.YELLOW );
		graaf.addEdge( p21, p22, Color.YELLOW );
		graaf.addEdge( p21, pFinish, Color.BLACK );
		graaf.addEdge( p22, p17, Color.YELLOW );
		spel.setMaze( graaf );
		assertEquals( "[]", spel.findPath( speler, pFinish ).toString() );
	}
}
